//
//  QzoneClient.m
//  Yueshi
//
//  Created by Northwan on 15/9/14.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "QzoneClient.h"
#import <TencentOpenAPI/TencentOAuth.h>
#import "TencentOpenAPI/QQApiInterface.h"


@interface QzoneClient()
@property (nonatomic,strong) TencentOAuth *tencentOAuth;
@end
@implementation QzoneClient

+ (QzoneClient *)sharedClient{
    static QzoneClient * singleClient;
    static dispatch_once_t pred;
    dispatch_once(&pred,^{
        singleClient=[[self alloc] initSingleton];
    } );
    return singleClient;
}

- (id)initSingleton
{
    self = [super init];
    if(self){
        _tencentOAuth = [[TencentOAuth alloc]initWithAppId:kQQAppId andDelegate:nil];
    }
    return self;
}

- (void)sendLinkContentWithURlStr:(NSString *)urlStr
                         andTitle:(NSString *)title
                      andImageURL:(NSString *)imageURL
                   andDescription:(NSString *)desc
{
    
    QQApiNewsObject *newsObj = [QQApiNewsObject
                                objectWithURL:[NSURL URLWithString:urlStr]
                                title: title
                                description:desc
                                previewImageURL:[NSURL URLWithString:imageURL]];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
    //将内容分享到qzone
    QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];
    //处理发送结果
    [self handleSendResult:sent];
}

- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
    switch (sendResult)
    {
        case EQQAPIAPPNOTREGISTED:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPIMESSAGECONTENTINVALID:
        case EQQAPIMESSAGECONTENTNULL:
        case EQQAPIMESSAGETYPEINVALID:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPIQQNOTINSTALLED:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPIQQNOTSUPPORTAPI:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPISENDFAILD:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        default:
        {
            break;
        }
    }
}

@end
